﻿using System;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.MySQL;
using Volo.Abp.Modularity;

using WorkflowEngine.Entitys;
using WorkflowEngine.IRepositorys;
using WorkflowEngine.Repositorys;

namespace WorkflowEngine.EntityFrameworkCore;

[DependsOn(
    typeof(WorkflowEngineDomainModule),
    typeof(AbpEntityFrameworkCoreModule)
    )]
public class WorkflowEngineEntityFrameworkCoreModule : AbpModule
{
    public override void PreConfigureServices(ServiceConfigurationContext context)
    {
        WorkflowEngineEfCoreEntityExtensionMappings.Configure();
    }

    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        context.Services.AddAbpDbContext<WorkflowEngineDbContext>(options =>
        {
            options.AddDefaultRepositories(includeAllEntities: true);
            options.AddRepository<ActivityInstance, ActivityInstanceRepository> ();
            options.AddRepository<ActivityTaskInstance, ActivityTaskInstanceRepository> ();
            options.AddRepository<BillCode, BillCodeRepository> ();
            options.AddRepository<ObjectApp, ObjectAppRepository> ();
            options.AddRepository<WorkflowApp, WorkflowAppRepository> ();
            options.AddRepository<WorkflowApp, WorkflowAppRepository> ();
            options.AddRepository<WorkflowInstance, WorkflowInstanceRepository> ();
            options.AddRepository<WorkTask, WorkTaskRepository> ();
        });

        Configure<AbpDbContextOptions>(options =>
        {
                /* The main point to change your DBMS.
                 * See also WorkflowEngineMigrationsDbContextFactory for EF Core tooling. */
            options.UseMySQL();
        });
    }
}
